package demo_State;
//演示线程状态：new，runnable，terminated
public class State_Test1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread =new Thread(()->{
            //啥也不做、
            //这边用long是为了让他空执行更久一点，更好查看RUNNABLE现象
            //注意用int 如果条件给大了，到达最大值后，i再++，会变成复数进入死循环
            for (long i = 0; i <100_0000_0000l ; i++) {

            }
        });
        //启动线程之前记录一下线程状态
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());
        //启动线程
        thread.start();
        //线程运行中记录线程状态
        Thread.sleep(1);//让打印线程慢一点防止抢占当前main线程抢占太快了
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());
        //等待线程运行结束,记录线程状态
        thread.join();
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());

    }
}
